class Solution {
    public int jump0(int[] nums) {
        int[] minSteps = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            minSteps[i] = i;
        }
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j <= nums[i] && i+j < nums.length; j++) {
                minSteps[i+j] = Math.min(minSteps[i+j], minSteps[i]+1);
                if (i+j == nums.length - 1){
                    return minSteps[nums.length-1];
                }
            }
        }
        return minSteps[nums.length-1];
    }

    
    public int jump(int[] nums) {
        int step = 0, dist = 0, end = 0;
        for (int i = 0; i < nums.length-1; i++) {
            dist = Math.max(i+nums[i], dist); // 当前位置能访问到的最远距离
            if (i == end) {
                end = dist; // 当前步数能访问到的边界
                step++;     // 步数+1
            }
        }
        return step;
    }

}